#!/bin/bash
#automatically elaborate TB/RTL structure and extract pre-processor
#USAGE: bash ./script/autosim.sh $(TB_MODULE) $(TB_DIR) $(INCLUDE_DIR) $(REPORT_FILE) $(RTL_DIR) $(OBJ_DIR)
#ATTENTION: this script assumes your TB is not in same directory of RTL
#elaborate TB hierarchy
bash ./script/elaborate.sh $1 $2 $3 $4 &> ./temp/tb_elaborate.log
if ! test -s ./temp/elaborate_error;
then
    echo "TB elaborate failed!"
    exit -1
else #此处假定缺乏的模块一定是DUT
    RTL=$(cat ./temp/elaborate_error|sed '2,$d')
    bash ./script/elaborate.sh $RTL $5 $3 /tmp/tb_rtlscan >>./temp/tb_elaborate.log
    cat /tmp/tb_rtlscan >> $4
    if test -e ./temp/elaborate_error;
    then
        echo "DUT elaborate failed!"
        exit -1
    fi
fi
rm ./temp/elaborate_error &>/dev/null
#extract PREPROCESSOR
cat $4 |sed '2,$d'|xargs cat|sed -n '/\#PREPROCESS_START/,/\#PREPROCESS_END/p'>./temp/PREPROCESSOR.sh


